<template>
	<uni-list>
		<uni-list-item title="修改密码" :show-extra-icon="true" :extraIcon="{color: '#bfbfbf',size: '22',type: 'refresh'}"
			link="navigateTo" to="./changePassword" />
		<uni-list-item title="注销账户" :show-extra-icon="true"
			:extraIcon="{color: '#bfbfbf',size: '22',type: 'closeempty'}" @click="deleteAccount" clickable />
	</uni-list>
</template>

<script>
	export default {
		onBackPress(e) {
		// 这里可以自定义返回逻辑，比如下面跳转其他页面
			uni.switchTab({
				url: '/pages/my/my'
			});
			return true
		},
		methods: {
			// 注销当前用户
			deleteAccount() {
				var that = this;
				uni.showModal({
					'title': '注销账户',
					'content': '账户注销后您账户的一切数据都将被删除，您确定要注销账户吗?',
					'confirmText': '删除',
					'confirmColor': 'red',
					success: function(res) {
						if (res.confirm) {
							that.$http.request({
								url: '/organizations/web/user/cancellation',
								method: 'DELETE'
							}).then(res => {
								res = res.data;
								if (res.result) {
									uni.showToast({
										title: res.data
									})
									uni.showModal({
										title: '您的账户已注销!点击下方确定即退出登录!',
										showCancel: false,
										success: function(res) {
											// 退出登录
											uni.removeStorageSync("lhamster_identity_info")
											// 跳转到登录页
											uni.redirectTo({
												url: '../user/login'
											});
										}
									})
								} else {
									uni.showToast({
										title: res.data,
										icon: 'none'
									})
								}
							})
						}
					}
				});
			}
		}
	}
</script>

<style>
</style>
